package com.caiyi.financial.nirvana.sms.controller;

import com.caiyi.financial.nirvana.sms.entity.SmsAdmin;
import com.caiyi.financial.nirvana.sms.querybean.QueryBatchMsgBean;
import com.caiyi.financial.nirvana.sms.service.SmsAuditBatchService;
import com.youyu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "待审核短信批次管理")
@RestController
@RequestMapping("sms/admin/auditBatch")
public class SmsAuditBatchController {


    @Autowired
    private SmsAuditBatchService smsAuditBatchService;


    @ApiOperation(value = "根据params查找BatchMsgAudit详情", notes = "根据params查找BatchMsgAudit详情")
    @ApiImplicitParam(name = "bean", value = "查找审批批次参数", required = true, dataType = "QueryBatchMsgBean")
    @PostMapping("/getAuditBatchByParams")
    public Result getBatchAuditByParams(@RequestBody QueryBatchMsgBean bean) {
        return Result.ok(smsAuditBatchService.getBatchAuditByParams(bean));

    }


    @ApiOperation(value = "审批批次信息状态", notes = "审批批次信息状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batchIds", value = "批次编号，多个以逗号隔开", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "reason", value = "驳回原因", dataType = "String", paramType = "query")})
    @PostMapping("/updateBatchAuditByBatchId")
    public Result updateBatchAuditByBatchId(String batchIds, Integer status, String reason) {
        Subject subject = SecurityUtils.getSubject();
        SmsAdmin user = (SmsAdmin) subject.getPrincipal();
        return Result.ok(smsAuditBatchService.updateBatchAuditByBatchId(batchIds, status, user.getAccount(), reason));
    }

}
